﻿using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

// Models/User.cs
public class User
{
    [Key]
    public int Id { get; set; }

    [Required]
    [MaxLength(255)]
    public string Name { get; set; } = string.Empty;

    public DateTime CreatedAt { get; set; } = DateTime.UtcNow;

    public ICollection<Template> Templates { get; set; } = new List<Template>();
}

// Models/Project.cs
public class Project
{
    [Key]
    public int Id { get; set; }

    [Required]
    [MaxLength(255)]
    public string Name { get; set; } = string.Empty;

    public string? Description { get; set; }

    public ICollection<ProjectParameter> ProjectParameters { get; set; } = new List<ProjectParameter>();

    public ICollection<TemplateProject> TemplateProjects { get; set; } = new List<TemplateProject>();
}

// Models/Parameter.cs
public class Parameter
{
    [Key]
    public int Id { get; set; }

    [Required]
    [MaxLength(255)]
    public string Name { get; set; } = string.Empty;

    [Required]
    public string DataType { get; set; } = "String";  // Enum: String, Int, Float, Bool

    public string? DefaultValue { get; set; }

    public ICollection<ProjectParameter> ProjectParameters { get; set; } = new List<ProjectParameter>();

    public ICollection<TemplateProjectParameter> TemplateProjectParameters { get; set; } = new List<TemplateProjectParameter>();
}

// Models/ProjectParameter.cs
public class ProjectParameter
{
    [Key]
    public int Id { get; set; }

    [Required]
    public int ProjectId { get; set; }

    [ForeignKey(nameof(ProjectId))]
    public Project? Project { get; set; }

    [Required]
    public int ParameterId { get; set; }

    [ForeignKey(nameof(ParameterId))]
    public Parameter? Parameter { get; set; }

    [Required]
    public bool IsAdjustable { get; set; } = false;

    public string? FixedValue { get; set; }
}

// Models/Template.cs
public class Template
{
    [Key]
    public int Id { get; set; }

    [Required]
    [MaxLength(255)]
    public string Name { get; set; } = string.Empty;

    [Required]
    public int UserId { get; set; }

    [ForeignKey(nameof(UserId))]
    public User? User { get; set; }

    public DateTime CreatedAt { get; set; } = DateTime.UtcNow;

    public ICollection<TemplateProject> TemplateProjects { get; set; } = new List<TemplateProject>();
}

// Models/TemplateProject.cs
public class TemplateProject
{
    [Key]
    public int Id { get; set; }

    [Required]
    public int TemplateId { get; set; }

    [ForeignKey(nameof(TemplateId))]
    public Template? Template { get; set; }

    [Required]
    public int ProjectId { get; set; }

    [ForeignKey(nameof(ProjectId))]
    public Project? Project { get; set; }

    [Required]
    public int SequenceOrder { get; set; }

    public ICollection<TemplateProjectParameter> TemplateProjectParameters { get; set; } = new List<TemplateProjectParameter>();
}

// Models/TemplateProjectParameter.cs
public class TemplateProjectParameter
{
    [Key]
    public int Id { get; set; }

    [Required]
    public int TemplateProjectId { get; set; }

    [ForeignKey(nameof(TemplateProjectId))]
    public TemplateProject? TemplateProject { get; set; }

    [Required]
    public int ParameterId { get; set; }

    [ForeignKey(nameof(ParameterId))]
    public Parameter? Parameter { get; set; }

    [Required]
    [MaxLength(255)]
    public string Value { get; set; } = string.Empty;
}